package cn.bgs.serviceoss.controller;


import cn.bgs.serviceoss.service.OssService;
import cn.bgs.serviceutils.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@Api(tags = "Alioss文件上传控制器")
@RequestMapping("/oss")
public class OssController {
    @Autowired
    private OssService ossService;

    //上传头像的方法
    @PostMapping("/upload")
    @ApiOperation(value = "上传头像")
    public R uploadOssFile(MultipartFile file) {
        //获取上传文件  MultipartFile
        //返回上传到oss的路径
        String url = ossService.uploadFileAvatar(file);
        return R.ok().data("url",url).message("文件上传成功");
    }


    //上传头像的方法
    @PostMapping("/uploadApp")
    @ApiOperation(value = "APP上传头像")
    public String uploadApp(MultipartFile file) {
        //获取上传文件  MultipartFile
        //返回上传到oss的路径
        String url = ossService.uploadFileAvatar(file);
        return url;
    }


    //APP上传图片
    @PostMapping("/uploadAppImg")
    @ApiOperation(value = "APP上传图片")
    public String uploadAppImg(MultipartFile file) {
        //获取上传文件  MultipartFile
        //返回上传到oss的路径
        String url = ossService.uploadFileAvatars(file);
        return url;
    }


    @PostMapping("/wordToPdf")
    @ApiOperation(value = "文件导出")
    public R  wordToPdf(@RequestBody MultipartFile file){
        String uu =ossService.wordToPdf(file,"doc");
        return R.ok().data("uu",uu);
    }

}
